package com.acceptable.qucun.file.entity;

import com.acceptable.qucun.generic.util.TimeUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import org.springframework.lang.NonNull;

import java.time.LocalDateTime;

/**
 * <p>
 * 
 * </p>
 *
 * @author 巴斯罗斯·K·赫斯洛利
 * @since 2021-08-29
 */
@TableName("file_share")
public class FileShare extends Model<FileShare> {

    private static final long serialVersionUID=1L;

    /**
     * 此次分享操作的id
     */
    @TableId(value = "share_id", type = IdType.INPUT)
    private Integer shareId;

    /**
     * 此次分享操作的时间
     */
    @TableField("share_time")
    private LocalDateTime shareTime;

    /**
     * 此次分享的到期时间
     */
    @TableField("expire_time")
    private LocalDateTime expireTime;

    /**
     * 此次分享的提取码
     */
    @TableField("password")
    private String password;

    /**
     * 此次分享的文件的原主人
     */
    @TableField("user_id")
    private Integer userId;

    @TableField("url")
    private String url;

    public Integer getShareId() {
        return shareId;
    }

    public void setShareId(Integer shareId) {
        this.shareId = shareId;
    }

    public LocalDateTime getShareTime() {
        return shareTime;
    }

    public void setShareTime(LocalDateTime shareTime) {
        this.shareTime = shareTime;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setPartFieldByShareInfo(@NonNull ShareInfo info){
        this.shareId = info.getShareId();
        this.url = info.getUrl();
        this.password = info.getPassword();

        this.shareTime = TimeUtil.date2LocalDateTime(TimeUtil.string2Date(info.getShareTime()));
        this.expireTime = TimeUtil.date2LocalDateTime(TimeUtil.string2Date(info.getExpireTime()));

    }

    @Override
    public String toString() {
        return "FileShare{" +
                "shareId=" + shareId +
                ", shareTime=" + shareTime +
                ", expireTime=" + expireTime +
                ", password=" + password +
                ", userId=" + userId +
                ", url='" + url + '\'' +
                '}';
    }
}
